package org.gw.building.repositories;

import org.gw.building.model.Bm;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by qwx89 on 2017/7/23.
 */
public interface BmRepository extends CrudRepository<Bm, String> {
  @Query("from Bm t where (?1 is null or t.mc like ?1) and (?2 is null or t.cc.dm = ?2) and (?3 is null or t.sfyx = ?3) " +
          " and (?4 is null or t.ssyx = ?4) order by t.px desc")
  Page<Bm> queryBm(String mc, String cc, Boolean sfyx, String departmentId, Pageable pageable);

  @Query("from Bm t where  t.cc.dm < ?1 and t.ssyx = ?2 order by t.px desc")
  List<Bm> queryLsbm(String cc, String ssyx);

  @Query("select max(t.px) from Bm t where t.ssyx = ?1")
  int queryBmMaxPx(String departmentId);

  @Query("from Bm t where t.ssyx = ?1")
  List<Bm> findBySsyx(String departmentId);
}
